package Messages;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import ocsf.server.ConnectionToClient;
import server.SQLConnection;
/**
 * This class implements show assignment from the DB 
 * @author Gabi Revah
 * @author Aviad Almog
 */ 
public class MessageShowAssignment {
	private ConnectionToClient client ;
	private String[] str; 
	/**
	 * Constructor of this class 
	 * @param str
	 * @param client
	 */
	public MessageShowAssignment(String[] str, ConnectionToClient client) {
	
		this.client= client ;
		this.str= str; 
	}
	/**
	 * This method gets all the assignments from the DB
	 * @throws SQLException
	 * @throws IOException
	 */
	public void ShowAssign() throws SQLException, IOException{
		
		SQLConnection sc = new SQLConnection();
		
		java.sql.PreparedStatement ps = sc.getConnection().prepareStatement("SELECT * FROM db.assingment order by date");
		ResultSet AssignRes= ps.executeQuery();
		ArrayList<Object> assign=new ArrayList<Object>();
		assign.add("ShowAssign");
		while (AssignRes.next())
		{
			assign.add(AssignRes.getInt(1));
			assign.add(AssignRes.getString(2));
			assign.add(AssignRes.getString(4));
			assign.add(AssignRes.getString(5));
			assign.add(AssignRes.getString(6));
		}
		client.sendToClient(assign);
	}
}
